package com.wenwenli.boot.context;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SpringApplication {
    private static boolean inited = false;
    private static String BASE_PACKAGE_NAME;

    private static Map<String, Object> beans = new ConcurrentHashMap<String, Object>();

    public static ApplicationContext run(Class clazz) throws Exception {
        BASE_PACKAGE_NAME = clazz.getPackage().getName();
        return initWebApplicationContext();

    }
    public static ApplicationContext run(String  basePackage) throws Exception {
        BASE_PACKAGE_NAME = basePackage;
        return initWebApplicationContext();

    }

    private  synchronized static ApplicationContext initWebApplicationContext() throws Exception {
        if (inited) {
            throw new RuntimeException("ioc has start up ");
        }
        inited = true;
        return ApplicationContext.getInstance().initContext(BASE_PACKAGE_NAME);
    }

}
